﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');

FantastPlatform.UI.PersonTaskForm = function (config) {
    Ext.apply(this, config);
    var newWidth = this.width;
    var newHeight = this.height;
    var thispoliceNum = this.policemanNumber;
    var grid1 = new FantastPlatform.UI.PersonTaskGrid({
        url: '../Service/PersonTaskService.aspx?Action=GetPersonByTaskId?Id=' + this.taskId,
        taskId: this.taskId,
        height: newHeight / 2,
        tbar: [{
            text: '移出人员',
            iconCls: 'delete',
            handler: removeRole
        }]
    });
    grid1.onUpdataGrid();

    var grid2 = new FantastPlatform.UI.PersonTaskUnitGrid({
        url: '../Service/PersonTaskService.aspx?Action=GetPersonByOrgCode',
        height: newHeight / 2,
        tbar: [{
            text: '添加人员',
            iconCls: 'add',
            handler: addRole
        }]
    })
    grid2.onUpdataGrid();

    var uSearchInfo = new Ext.form.FormPanel
    ({
        border: false,
        title: '查询条件',
        split: true,
        url: '../Service/PersonTaskService.aspx?Action=GetPolice',
        style: 'border:solid 1px',
        labelWidth: 50,
        bodyStyle: 'padding:5px 5px 0',
        height: newHeight,
        defaultType: 'textfield',
        collapsible: true,
        defaults: { width: 120 },
        tbar: ['从警员列表中查询'],
        items: [{
            fieldLabel: '姓名',
            name: 'name'
        }, {
            fieldLabel: '警号',
            name: 'Code'
        }],
        buttons: [{
            text: '提交查询',
            handler: function () { onPoliceSearchClick(uSearchInfo, grid2, null); }
        }]
    });

    this.items = [{
        columnWidth: .7,
        width: 500,
        height: newHeight / 2,
        border: false,
        items: [grid1]
    }, {
        columnWidth: .7,
        width: 500,
        height: newHeight / 2,
        border: false,
        items: [grid2]
    }, {
        columnWidth: .3,
        width: 160,
        height: newHeight,
        border: false,
        items: [uSearchInfo]
    }];

    var RoleId = this.roleId;
    function removeRole() {
        var node = checkGridSelected(grid1);
        if (node) {
            if (getIdFromGrid(node, 'Number') == thispoliceNum) {
                Ext.Msg.alert('提示', '不能将自己从该执勤表中移除');
            }
            else {
                Ext.Msg.confirm('提示', '确认要移除执勤列表中已有的警员？', function (btn) {
                    if (btn == 'yes') {
                        Ext.Msg.wait('正在移除执勤中已有警员……', '移除');
                        var fIds = getIdFromGrid(node, 'Id');
                        ajaxCalled(null, '../Service/PersonTaskService.aspx?Action=RemoveUser&Id=' + grid1.tsakId, fIds, grid1, null);
                    }
                });
            }
        }
    }

    function addRole() {
        var node = checkGridSelected(grid2);
        if (node) {
            Ext.Msg.confirm('提示', '确认要添加警员到执勤表中？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在警员到执勤中……', '添加');
                    var fIds = getIdFromGrid(node, 'Id');
                    //alert(fIds);
                    ajaxCalled(null, '../Service/PersonTaskService.aspx?Action=AddUser&Id=' + grid1.tsakId, fIds, grid1, null);
                }
            })
        }
    }

    function onPoliceSearchClick(form, grid, sender, fn) {
        if (form.form.isValid()) {
            var name = form.form.getValues().name;
            var Code = form.form.getValues().Code;
            grid2.store.removeAll();
            grid2.store.proxy.conn = { method: 'post', url: '../Service/PersonTaskService.aspx?Action=GetPolice' };
            grid2.store.load({ params: { start: 0, limit: grid2.paperBar.getPageNumber(), dir: '', sort: '', code: Code, name: name} });
        }
    }
    FantastPlatform.UI.PersonTaskForm.superclass.constructor.call(this, {
        layout: 'column',
        border: false
    });
};

Ext.extend(FantastPlatform.UI.PersonTaskForm, Ext.Panel, {

});